﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ThaireInvestmentWeb.Util;
using ThaireInvestmentWeb.WcfSerivce;

namespace ThaireInvestmentWeb.Models
{
    public class EditExtraInstallmentModel
    {
        public LoanExtraInstallmentScreenData ScreenData { get; set; }
        public LoansHeader Header { get; set; }
        public LoansExtrainstallment Extrainstallment { get; set; }
        public EditExtraInstallmentModel()
        {
            Init();
        }
        void Init()
        {
            if (null == Header)
                Header = new LoansHeader();
            if (null == Extrainstallment)
                Extrainstallment = new LoansExtrainstallment();

            var defaultItem = WebUtil.SelectListSelectDefault();
        }

        public static EditExtraInstallmentModel BuildModel(LoanExtraInstallmentScreenData data)
        {
            var model = new EditExtraInstallmentModel {ScreenData = data};
            if (data.HeaderDTO != null && data.HeaderDTO.Header != null)
                model.Header = data.HeaderDTO.Header;
            if (data.Extrainstallment != null)
                model.Extrainstallment = data.Extrainstallment;

            model.HeaderID = model.Header.LoansHeaderID;
            model.ExtrainstallmentID = model.Extrainstallment.LoansExtrainstallmentID;

            if (data.Extrainstallment != null)
                model.UpdateMode = true;

            return model;
        }


        #region adapter data
        public int HeaderID
        {
            get
            {
                return Extrainstallment.LoansHeaderID.GetValueOrDefault();
            }

            set
            {
                Extrainstallment.LoansHeaderID = value;
            }
        }
        public int ExtrainstallmentID
        {
            get
            {
                return Extrainstallment.LoansExtrainstallmentID;
            }

            set
            {
                Extrainstallment.LoansExtrainstallmentID = value;
            }
        }

        //[DataType(DataType.Date)]
        //[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        //[Display(Name = "Maturity Date")]
        //public DateTime? HeaderMaturityDate
        //{
        //    get { return Header.MaturityDate; }
        //    set { Header.MaturityDate = value; }
        //}

        //[Required(ErrorMessage = "โปรดระบุ")]
        //public string RefNo
        //{
        //    get { return Transaction.RefNO; }
        //    set { Transaction.RefNO = value; }
        //}

        //[Required(ErrorMessage = "โปรดระบุ")]
        //[DataType(DataType.Date)]
        //[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        //[Display(Name = "Trade Date")]
        //public DateTime? TradeDate
        //{
        //    get { return Transaction.TradeDate; }
        //    set { Transaction.TradeDate = value; }
        //}
        //[Required(ErrorMessage = "โปรดระบุ")]
        //[DataType(DataType.Date)]
        //[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        //[Display(Name = "Settlement Date")]
        //public DateTime? SettlementDate
        //{
        //    get { return Transaction.SettlementDate; }
        //    set { Transaction.SettlementDate = value; }
        //}

        //[Required(ErrorMessage = "โปรดระบุ")]
        //public int? Unit
        //{
        //    get { return Transaction.Unit; }
        //    set { Transaction.Unit = value; }
        //}
        
        #endregion


        public String SubmitBtn { get; set; }
        public String CancelBtn { get; set; }
        public bool UpdateMode { get; set; }

    }
}